﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccessLayer;
using BusinessLogicLayer;

namespace PresentationLayer
{
    public partial class ViewDisbursementHistoryDetail : System.Web.UI.Page
    {
        DisbursementHistoryControl dhc = new DisbursementHistoryControl();
        StationeryInventoryEntities1 ent = new StationeryInventoryEntities1();

        int cPDetailID;
        String Status;
        int deptReqID;
        String userName;
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                String colldate = Request.QueryString["colldate"];
                DateTime collDate = Convert.ToDateTime(colldate);
                String collPoint = Request.QueryString["collpoint"];
                Status = Request.QueryString["status"];
                String deptRId = Request.QueryString["deptreqid"];
                deptReqID = Convert.ToInt32(deptRId);
                userName = Request.QueryString["username"];
                //added by 19/3
                String colltime = Request.QueryString["colltime"];
                //String collPointDetId = Request.QueryString["collPointDetID"];

                lblDate.Text = collDate.ToShortDateString();
                lblDepartment.Text = dhc.getDepartmentName(deptReqID).ToString();
                lblCollectionPoint.Text = collPoint;
               // lblCollectionTime.Text = collDate.ToShortTimeString();
                lblCollectionTime.Text = colltime;


                int repid = Convert.ToInt32(dhc.getRepID(deptReqID));
                int empid = Convert.ToInt32(dhc.getEmpID(userName));

                if (!IsPostBack)
                {
                    Binding();
                }

                if (Status == "Pending")
                {
                    lblStatus.Text = "Pending";
                    btnConfirm.Visible = false;
                    lblRepName.Text = dhc.getRepName(deptReqID).ToString();
                }
                else if (Status == "Confirmed By Store Clerk")
                {
                    lblStatus.Text = "Confrimed By Store Clerk";
                    lblRepName.Text = dhc.getRepName(deptReqID).ToString();
                    if (Convert.ToInt32(dhc.getRepID(deptReqID)) == Convert.ToInt32(dhc.getEmpID(userName)))
                    {
                        btnConfirm.Visible = true;
                    }
                    else
                    {
                        btnConfirm.Visible = false;
                    }
                }
                else
                {
                    lblStatus.Text = "Collected";
                    btnConfirm.Visible = false;
                    lblRepName.Text = dhc.getRepNameCollected(deptReqID).ToString();
                }
            }
            catch (Exception ex)
            { 
            
            }
            

        }

        public void Binding()
        {
                dgvDDetailList.DataSource = dhc.getDDList(deptReqID);
                dgvDDetailList.DataBind();
            
        }

        protected void btnConfirm_Click(object sender, EventArgs e)
        {
            try
            {
                int repID = Convert.ToInt32(dhc.getRepID(deptReqID));
                String repName = lblRepName.Text;
                dhc.addRepName(deptReqID, repID);
                lblStatus.Text = "Collected";
                btnConfirm.Visible = false;
            }
            catch
            { 
            
            }
            
        }

    }
}